package com.dycong.common.IO.calculator.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created by dycong on 2017/3/24.
 */
public class ClientWriter implements Runnable {
    static Socket socket=null;
    public ClientWriter(Socket socket){
        this.socket=socket;
    }
    @Override
    public void run(){
     send();
    }
    public static void send() {
        BufferedReader in = null;
        PrintWriter out = null;
        try {
            out = new PrintWriter(socket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(System.in));
            String message = "";
            while (true) {
                if ((message = in.readLine()) == null) continue;
                out.println(message );            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                in = null;
            }
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                socket = null;
            }
        }
    }
}
